package com.yida.gwj.expend.controller;

import java.util.List;

import javax.validation.constraints.NotEmpty;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yida.common.core.web.controller.BaseController;
import com.yida.common.core.web.domain.AjaxResult;
import com.yida.common.security.annotation.RequiresPermissions;
import com.yida.gwj.expend.domain.GwjMaintenanceFundsBusinessAttachment;
import com.yida.gwj.expend.domain.dto.Appropriate4ApproveDTO;
import com.yida.gwj.expend.domain.dto.GetAttachmentInfoRequest;
import com.yida.gwj.expend.domain.request.InsertAttachmentInfoRequest;
import com.yida.gwj.expend.service.IGwjMaintenanceFundsBusinessAttachmentService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 上传材料图片地址Controller
 *
 * @author lgp
 * @date 2023-03-21
 */
@Validated
@Api(value = "附件材料信息业务", tags = "附件材料信息业务")
@RestController
@RequestMapping("/expend/attachment")
public class GwjMaintenanceFundsBusinessAttachmentController extends BaseController {

    @Autowired
    private IGwjMaintenanceFundsBusinessAttachmentService gwjMaintenanceFundsBusinessAttachmentService;

    @ApiOperation(value = "查询附件材料信息业务列表", response = GwjMaintenanceFundsBusinessAttachment.class)
    @RequiresPermissions("gwj:attachment:list")
    @GetMapping("/list")
    public AjaxResult list(GetAttachmentInfoRequest getAttachmentInfoRequest) {
        return AjaxResult.success(gwjMaintenanceFundsBusinessAttachmentService.getGwjMaintenanceFundsBusinessAttachmentList(getAttachmentInfoRequest));
    }

    @ApiOperation(value = "获取附件材料信息业务详细信息", response = GwjMaintenanceFundsBusinessAttachment.class)
    @RequiresPermissions("gwj:attachment:query")
    @GetMapping(value = "/{attachmentId}")
    public AjaxResult getInfo(@PathVariable("attachmentId") Long attachmentId) {
        return AjaxResult.success(gwjMaintenanceFundsBusinessAttachmentService.selectGwjMaintenanceFundsBusinessAttachmentByAttachmentId(attachmentId));
    }

    @ApiOperation(value = "修改附件材料信息业务信息")
    @RequiresPermissions("gwj:attachment:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody GwjMaintenanceFundsBusinessAttachment gwjMaintenanceFundsBusinessAttachment) {
        return toAjax(gwjMaintenanceFundsBusinessAttachmentService.updateGwjMaintenanceFundsBusinessAttachment(gwjMaintenanceFundsBusinessAttachment));
    }

    @ApiOperation(value = "删除附件材料信息业务信息")
    @RequiresPermissions("gwj:attachment:remove")
    @DeleteMapping("/{attachmentIds}")
    public AjaxResult remove(@PathVariable Long attachmentIds) {
        return toAjax(gwjMaintenanceFundsBusinessAttachmentService.deleteGwjMaintenanceFundsBusinessAttachmentByAttachmentId(attachmentIds));
    }

    @ApiOperation(value = "新增上传材料图片地址")
    @RequiresPermissions("gwj:attachment:add")
    @PostMapping
    public AjaxResult insertAttachmentInfo(@Validated @RequestBody InsertAttachmentInfoRequest insertAttachmentInfoRequest) {
        return AjaxResult.success(gwjMaintenanceFundsBusinessAttachmentService.insertAttachmentInfo(insertAttachmentInfoRequest));
    }

    @ApiOperation(value = "通过字段转换得到content实体")
    @RequiresPermissions("gwj:attachment:list")
    @GetMapping("/getContent2Entity")
    public AjaxResult getContent2Entity(Integer serverType, String serverIdentification, String... fieldName) {
        return AjaxResult.success(gwjMaintenanceFundsBusinessAttachmentService.getContent2Entity(Appropriate4ApproveDTO.class, serverType, serverIdentification, fieldName));
    }

    @ApiOperation(value = "多附件材料上传")
    @RequiresPermissions("gwj:attachment:add")
    @PostMapping("/batchInsert")
    public AjaxResult batchInsertAttachmentInfo(@RequestBody @NotEmpty(message = "文件不能为空") List<InsertAttachmentInfoRequest> insertAttachmentInfoRequestList) {
        return toAjax(gwjMaintenanceFundsBusinessAttachmentService.batchInsertAttachmentInfo(insertAttachmentInfoRequestList));
    }

    // --------------------------新增功能区 hmh start-------------------
    @ApiOperation(value = "批量取消收件")
    @RequiresPermissions("gwj:expend:appropriate:edit")
    // @GetMapping("/batch/cancel/receipt/{attachmentIds}")
    @GetMapping(value = "/batch/cancel/receipt/{attachmentIds}")
    public AjaxResult batchCancelReceipt(@PathVariable Long[] attachmentIds) {
        return toAjax(gwjMaintenanceFundsBusinessAttachmentService.batchCancelReceipt(attachmentIds));
    }
    // --------------------------新增功能区 hmh end-------------------

}
